<html>
<head>
<title>Wiki table for [[Hattrick]]</title>
</head>
<body>
<?php

require_once('database.inc.php');
require_once('track.inc.php');

hit();

$dbh = connect_db("gene");

if (!$query = mysql_query("SELECT count(leagueid) nl, sum(activeusers) sa, format(sum(activeusers),0) saf, sum(numberofteams) sn, format(sum(numberofteams),0) snf FROM leagues WHERE leagueid != 255",$dbh)) die (mysql_error());
$row = mysql_fetch_array($query);

$nl = $row['nl']; $sa = $row['sa']; $sn = $row['sn']; $saf = $row['saf']; $snf = $row['snf'];

if (!$query = mysql_query("SELECT continent, count(leaguename) nl, format(sum(activeusers),0) sa, format(sum(numberofteams),0) sn, round(100*sum(activeusers) / $sa , 1) pa, round(100*sum(numberofteams) / $sn , 1) pn FROM `leagues` WHERE leagueid != 255 GROUP BY Continent ORDER BY pa DESC", $dbh)) die (mysql_error());
?>
<pre>
{| class="wikitable" style="float:left; text-align:right" |
| colspan="6" bgcolor="#e5e5e5" style="text-align:center" | '''Continental Distribution of Hattrick Teams &lt;ref&gt;Copied from http://websec.science.uva.nl/~lhoek/wikitable.php&lt;/ref&gt;'''
|-
! Continent !! Leagues !! Total Users !! % Users !! Total Teams !! % Teams
<?php
while ($row = mysql_fetch_array($query)) {
	echo "|-\n| style=\"text-align:left\" | [[{$row['continent']}]] || {$row['nl']} || {$row['sa']} || {$row['pa']}% || {$row['sn']} || {$row['pn']}%\n"; 
}
?>
|- 
| || || || || ||
|- 
<?php
echo "| style=\"text-align:left\" | '''Total''' || '''$nl''' || '''$saf''' || '''100%''' || '''$snf''' || '''100%'''\n";
?>
|- 
| colspan="8" style="border:1px solid white; background-color:#fff; text-align:left" | ''Data current as of <?php echo date("j M, Y"); ?>''
|}
</pre>
</body>
</html>
